package com.example.yan.excel_split.controller;

import cn.hutool.json.JSONArray;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.alibaba.fastjson.JSON;

import com.alibaba.fastjson.JSONObject;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class demo5 {

    public static void main(String[] args) {

        ExcelReader fileReader = ExcelUtil.getReader("C:\\Users\\75763\\Desktop\\新建 Microsoft Excel 工作表.xlsx");
        List<List<Object>> readAll = fileReader.read();
        System.out.println(readAll);

        System.out.println(JSON.toJSONString(readAll));

        String[] keyArr = new String[]{"ID", "金额"};


        JSONArray array = new JSONArray();
        for (List<Object> aLinelist : readAll) {
            if (aLinelist.size() < keyArr.length)//匹配数据长度 长度不足不要
                continue;
            Map<Object, Object> map = new HashMap<>();
            for (int i = 0; i < keyArr.length; i++) {
                if (i < aLinelist.size()) {
                    Object property = aLinelist.get(i);
                    map.put(keyArr[i], property);
                }
            }
            array.add(map);
        }
      //  System.out.println("==>"+array);


        for (Object object :array){


            JSONObject object1 = JSON.parseObject(object.toString());
            String id1 = object1.getString("ID");
            String s = object1.getString("金额");
           // System.out.println(id1+","+s);
            String id = object1.getString("ID");
         //  id1.split(" ",2);
            if (id1.contains("2")) {
                System.out.println("6666"+id1);
            }

        }


    }

}
